﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Text;
using MpSoft.Library.BUSS.Contents;
using MpSoft.Library.BUSS.Categories;
using MpSoft.Basic.Utils;

namespace MpSoft.Web.Controls.News
{
    public partial class NewsDetailControl : System.Web.UI.UserControl
    {
        #region Var

        private int ItemID = 0;
        private string CategorySeName = string.Empty;

        #endregion

        #region Method

        protected string GetNews()
        {
            if (ItemID > 0)
            {
                var obj = NewsBUSS.News_ByID(ItemID);
                if (obj != null)
                {
                    StringBuilder sb = new StringBuilder();
                    sb.Append("<h1>" + obj.Title + "</h1>");
                    sb.Append("<h3>" + obj.Description + "</h3>");
                    sb.Append("<div class='news-content'>" + obj.Content + "</div>");
                    return sb.ToString();
                }
            }
            return "";
        }

        protected string NewsOrther()
        {
            if (!string.IsNullOrEmpty(CategorySeName))
            {
                //string key = CommonHelper.CreateUrlKey(CategorySeName);
                var objCate = CategoryBUSS.Category_BySeName(CategorySeName);
                var newsOrther = NewsBUSS.News_List(objCate.CategoryID, 1, 1);
                StringBuilder sb = new StringBuilder();
                string url = "";
                foreach (var news in newsOrther)
                {
                    url = string.Format(news.FormatUrl, news.NewsID);
                    sb.Append("<a title='" + news.Title + "' href='" + url + "'>" + news.Title + "</a>");
                }
                return sb.ToString();
            }
            return "";
        }

        #endregion

        #region Event
        
        protected void Page_Load(object sender, EventArgs e)
        {
            if (Request.QueryString["ItemID"] != null)
                int.TryParse(Request.QueryString["ItemID"].ToString(), out ItemID);
            if (Request.QueryString["CategoryCode"] != null)
                CategorySeName = Request.QueryString["CategoryCode"].ToString();
        }
        
        #endregion

        #region Properties
        #endregion
    }
}